package com.cfpl.admin_service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfpl.admin_service.VO.PageQueryCondition;
import com.cfpl.admin_service.service.VegetableManagementService;
import com.cfpl.project_common.pojo.VegetableManagement;
import com.cfpl.project_common.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.PathContainer;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: wrp
 * @Date: 2023/10/19 - 21:16
 * @Description: com.cfpl.admin_service.controller
 * @version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/vegetableManage")
@Api(tags="果蔬管理相关接口")
public class VegManagementController{

    @Autowired
    private VegetableManagementService vegManService;

    /**
     * 功能描述：分页查询果蔬管理
     * @param currentPage 当前页
     * @param pageSize 每页条数
     * @param condition 查询条件
     * @return 分页对象
     */
    @ApiOperation("分页查询果蔬管理")
    @GetMapping("/queryAllVegMan")
    public BaseResult<PageQueryCondition> queryAll(int currentPage, int pageSize, String condition) {
        Page<VegetableManagement> page = vegManService.querypage(currentPage, pageSize,condition);
        PageQueryCondition queryCondition = new PageQueryCondition(page,condition);
        return BaseResult.ok(queryCondition);
    }
    /**
     * 新增一条果蔬管理对象
     * @param vegMan 果蔬管理对象
     * @return
     */
    @ApiOperation("新增一条果蔬管理对象")
    @PostMapping("/addVegMan")
    public BaseResult<String> addVegMan(@RequestBody VegetableManagement vegMan) {
        vegManService.addVegMan(vegMan);
        return BaseResult.ok(" add success");
    }
    /**
     * 功能描述：根据id查询一条果蔬管理对象
     * @param id 果蔬管理对象ID
     * @return 果蔬管理对象
     */
    @ApiOperation("查询一条果蔬管理对象")
    @GetMapping("/queryVegManById/{id}")
    public BaseResult<VegetableManagement> queryVegManById(@PathVariable("id")Long id) {
        VegetableManagement vegMan = vegManService.queryVegManById(id);
        return BaseResult.ok(vegMan);
    }

    /**
     * 功能描述：修改果蔬对象
     * @param vegMan 果蔬对象
     * @return 果蔬对象
     */
    @ApiOperation("修改果蔬管理对象")
    @PutMapping("/modifyVegMan")
    public BaseResult modifyVegMan(@RequestBody VegetableManagement vegMan) {
        vegManService.updateVegMan(vegMan);
        return BaseResult.ok(vegMan);
    }

    /**
     * 功能描述：删除果蔬管理对象
     * @param id 果蔬管理ID
     * @return 删除成功信息
     */
    @ApiOperation("删除一条果蔬管理对象")
    @DeleteMapping("/deleteVegMan/{id}")
    public BaseResult<String> deleteVegMan(@PathVariable("id")Long id) {
        vegManService.removeVegManById(id);
        return BaseResult.ok("delete success");
    }
    /**
     * 批量删除果蔬管理对象
     * @param Ids  农果蔬管理id列表
     * @return 删除成功信息
     */
    @ApiOperation("批量删除果蔬管理对象")
    @DeleteMapping("/deleteVegManList")
    public BaseResult<String> deleteVegManList(@RequestParam List<Long> Ids) {
        vegManService.deleteBatchByIds(Ids);
        return BaseResult.ok("delete success");
    }
}
